<template>
	<!-- 扫脸识人 -->
	<view id="container">
		<view class="content">
			<view class="title">请正对手机，确保光线充足</view>
			<image :src="imgpath||'https://z3.ax1x.com/2021/09/02/hri6oT.png'" mode="aspectFill" ></image>
		</view>
		<view class="tips">注意事项</view>
		<view class="tips-item">
			<view class="face">
				<image :src="rpath||'https://z3.ax1x.com/2021/09/02/hrihl9.png'" class="icon"></image>
				<view class="txt">不能遮挡面部</view>
			</view>
			<view class="active">
				<image src="https://z3.ax1x.com/2021/09/02/hriDLq.png" class="icon"></image>
				<view class="txt">放慢动作</view>
			</view>
		</view>

		<view class="btn" @click="start">开始识别</view>

		<view class="bottom-tips">
			<image src="../../static/sweep-face/jm.png" class="icon"></image>
			<view class="txt">信息已加密，仅用于身份验证</view>
		</view>
		
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	
	import {getImageData,getFloatLocationByExif}  from '../../js_sdk/iz-exif/js_sdk/izExif/izExif.js'
	var img_tool = require('image-tools')
	export default {
		data() {
			return {
				imgpath: '',
				rpath:''
			};
		},
		methods: {
			// 拍摄人脸 进行人脸识别
			start() {
				let that = this
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original'],
					sourceType: ['camera'],
					success: function(res) {
						let imgPath = res.tempFilePaths[0]
						that.imgpath=imgPath;
						(async()=>{
							
							let dir = 0
							// console.log("that.vuex_sysinfo.indexOf('iOS')===",that.vuex_sysinfo.indexOf('iOS'))
							if(that.vuex_sysinfo.indexOf('iOS')!=-1){
								dir=0
							}else{
								let imginfo = await getImageData(imgPath)
								dir = imginfo.exif.Orientation
							}
							
							let bs64 = await that.$u.utils.local_img2base64(imgPath,dir)
							
							that.$u.api.face_recognise({
								chars:bs64,
							}).then(res=>{
								if(res.code!=200){
									that.$refs.uToast.show({
										title: res.msg,
										type: 'error'
									})
									uni.showToast({
										title:res.msg,
										icon:'none'
									})
								}else{
									uni.showToast({
										title:'识别成功',
										icon:'none'
									})
									uni.navigateTo({
										url:'../scan-face/scan-result?data='+JSON.stringify(res.data)
									})
								}
							})
						})()
						
					}
				})
				
			}
		}
	}
</script>

<style lang="scss">
	#container {
		.content {
			text-align: center;

			.title {
				font-size: 13px;
				color: #818181;
				// padding: 64rpx 0 33rpx 0;
			}

			.img {
				width: 411rpx;
				height: 411rpx;
				padding-bottom: 53rpx;
			}
		}

		.tips {
			width: 750rpx;
			height: 61rpx;
			line-height: 61rpx;
			padding-left: 32rpx;
			background: #F0F0F0;
			font-size: 11px;
			color: #343434;
		}

		.tips-item {
			text-align: center;
			display: flex;
			justify-content: space-around;
			margin: 49rpx 0 67rpx 0;

			.icon {
				width: 90rpx;
				height: 90rpx;
			}

			.txt {
				font-size: 11px;
				color: #000;
			}
		}

		.btn {
			width: 572rpx;
			height: 90rpx;
			line-height: 90rpx;
			color: #fff;
			text-align: center;
			background: linear-gradient(90deg, #69DEE8, #52D2CF);
			border-radius: 45rpx;
			margin: 0 auto;
		}

		.bottom-tips {
			display: flex;
			justify-content: center;
			align-items: center;
			margin-top: 90rpx;

			.icon {
				width: 38rpx;
				height: 40rpx;
				margin-right: 5rpx;
			}

			.txt {
				font-size: 9px;
				color: #000;
			}
		}
	}
</style>
